package com.onec.service.channel.service.impl;

import com.onec.service.api.dto.request.channel.ChannelTradeReq;
import com.onec.service.api.dto.response.channel.ChannelTradeResp;
import com.onec.service.api.enums.StatusEnum;
import com.onec.service.channel.dao.ChannelOrderDetailRepository;
import com.onec.service.channel.entity.ChannelInfo;
import com.onec.service.channel.entity.ChannelOrderDetail;
import com.onec.service.channel.service.ChannelOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author onec
 * @see
 * @since 20200821
 */
@Service
public class ChannelOrderDetailServiceImpl implements ChannelOrderDetailService {

    @Autowired
    ChannelOrderDetailRepository channelOrderDetailRepository;

    @Override
    public ChannelOrderDetail createChannelOrderDetail(ChannelTradeReq channelTradeReq, ChannelInfo channelInfo) {
        ChannelOrderDetail channelOrderDetail;
        return null;
    }

    /**
     * 更新订单状态：
     *
     * @param channelTradeResp
     * @return
     */
    @Override
    public ChannelOrderDetail updateChannelOrderDetail(ChannelTradeResp channelTradeResp) {
        ChannelOrderDetail channelOrderDetail = this.findByTradeNum(channelTradeResp.getTradeNum());
        channelOrderDetail.setStatus(StatusEnum.valueOf(channelTradeResp.getStatus()));
        channelOrderDetail.setRemarks(channelTradeResp.getMessage());
        return channelOrderDetailRepository.save(channelOrderDetail);
    }


    @Override
    public ChannelOrderDetail findByTradeNum(String tradeNum) {
        return channelOrderDetailRepository.findByTradeNum(tradeNum);
    }

    @Override
    public ChannelOrderDetail findBySerialNum(String serialNum) {


        return null;
    }
}
